package ru.spbu.math.seabattle.client.jms.common;

import javax.jms.JMSException;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;

public class JmsQueueHelper extends JmsHelper {

	protected Queue destination;

	@Override
	protected MessageProducer createProducer(Session session, String queueName) throws JMSException {
		initDestination(session, queueName);
		return session.createProducer(destination);
	}

	protected void initDestination(Session session, String queueName) throws JMSException {
		destination = session.createQueue(queueName);
	}

	@Override
	public Queue getDestination() {
		return destination;
	}

	public void addMessageListener(MessageListener messageListener) throws JMSException {
		session.createConsumer(destination).setMessageListener(messageListener);
	}

	@Override
	public void createSession(String url) throws JMSException {
		super.createSession(url);
	}

}
